package com.cytech.cloudclinic.adapter;

import android.widget.TextView;

import androidx.core.content.ContextCompat;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.cytech.cloudclinic.R;
import com.cytech.cloudclinic.bean.Action;
import com.cytech.cloudclinic.bean.AddDrugTag;

import java.util.List;

public class ActionChildAdapter extends BaseQuickAdapter<Action, BaseViewHolder>{
    //默认全部不选中
    private int currentPos = -1;

    public ActionChildAdapter(int layoutResId, List<Action> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, Action action) {
        TextView tv = baseViewHolder.getView(R.id.item_add_drug_tag_name);
        if(action.isAddData){
            tv.setText("      +      ");
            tv.setTextColor(ContextCompat.getColor(getContext(),R.color.colorPrimary));
            tv.setBackground(ContextCompat.getDrawable(getContext(),R.drawable.shape_round_empty_with_line_10));
        }else{
            tv.setText(action.value);
            if(baseViewHolder.getAdapterPosition()==currentPos){
                tv.setTextColor(ContextCompat.getColor(getContext(),R.color.colorPrimary));
                tv.setBackground(ContextCompat.getDrawable(getContext(),R.drawable.shape_round_real_bg_e9f2fe));
            }else{
                tv.setTextColor(ContextCompat.getColor(getContext(),R.color.color_333333));
                tv.setBackground(null);
            }
        }
    }

    public void setCurrentPos(int currentPos) {
        this.currentPos = currentPos;
        notifyDataSetChanged();
    }

    public int getSelectId(){
        if(currentPos==-1){
            return 0;
        }
        return getItem(currentPos).action_id;
    }
}
